package com.luminary.demo.user.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.luminary.component.trace.annotation.Trace;
import com.luminary.component.trace.tracker.SpringMvcTracker;
import com.luminary.demo.user.meta.UserApiConstants;
import com.luminary.demo.user.model.po.User;
import com.luminary.demo.user.service.UserService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RefreshScope
@RestController
@RequestMapping(UserApiConstants.ROOT_PATH)
public class UserApi {

	@Autowired
	private UserService userService;
	
	@Trace(SpringMvcTracker.class)
	@GetMapping(UserApiConstants.GET_USER_API)
	public User getUser(
			@PathVariable("username") String username,
			HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		log.info("username:" + username);
		return userService.findByUsername(username);
		
	}
	
}
